import axios from 'axios';

import {Message} from "element-ui";

const service = axios.create({
    // process.env.NODE_ENV === 'development' 来判断是否开发环境
    // easy-mock服务挂了，暂时不使用了
    //baseURL: 'http://192.168.1.53:9999/',
    timeout: 5000
});

service.interceptors.request.use(
    config => {
          var token = localStorage.getItem("token");
          if(token){
            config.headers.token=token;
          }
          return config;
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

service.interceptors.response.use(
    response => {
        if (response.status === 200) {
            return response;
        }else if(code===401){
            Message.error({
              title:'Forbidden',
              message:"权限不足，请及时联系管理员",
            })
          }  else {
            Message.error({
                title:"Forbidden",
                message:"服务器错误",
            })
            Promise.reject();
        }
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

export default service;
